using Commons.Models.Settings.Matchers.Operators;
using Commons.Models.Settings.Matchers.Operators.Relational;
using System;

namespace Commons.Models.Settings.Mappers
{
	public class RelationalOperatorMapper<T> : IMapper<string, IRelationalOperator<T>>
	{
		public IRelationalOperator<T> Map(string config)
		{
			string name = config.ToLower();

			if (OperatorType.Eq.Name.Equals(name))
			{
				return new EqualOperator<T>();
			}
			else if (OperatorType.Ge.Name.Equals(name))
			{
				return new GreaterEqualOperator<T>();
			}
			else if (OperatorType.Gt.Name.Equals(name))
			{
				return new GreaterThanOperator<T>();
			}
			else if (OperatorType.Le.Name.Equals(name))
			{
				return new LessEqualOperator<T>();
			}
			else if (OperatorType.Lt.Name.Equals(name))
			{
				return new LessThanOperator<T>();
			}
			else if (OperatorType.Ne.Name.Equals(name))
			{
				return new NotEqualOperator<T>();
			}
			else
			{
				throw new Exception("No Relational Operator defined for " + name);
			}
		}
	}
}

